# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: {{ elastic_cluster | upper }}
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: {{ ansible_hostname | lower }}
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: {{ elastic_path }}/elasticsearch
#
# Path to log files:
#
path.logs: /var/log/elasticsearch
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
bootstrap.memory_lock: {{ elastic_memory_lock | bool | to_json }}
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: {{ ansible_default_ipv4.address }}
#
# Set a custom port for HTTP:
#
http.port: {{ elastic_port_rest }}
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
{% if elastic_version.split('.')[0] == '7' %}
discovery.seed_hosts: ['{{ elastic_servers | list | join(":" + elastic_port_transport + "', '") }}:{{ elastic_port_transport }}']
cluster.initial_master_nodes: ['{{ elastic_servers | list | join(":" + elastic_port_transport + "', '") }}:{{ elastic_port_transport }}']
{% else %}
discovery.zen.fd.ping_timeout: 30s
discovery.zen.ping.unicast.hosts: ['{{ elastic_servers | list | join(":" + elastic_port_transport + "', '") }}:{{ elastic_port_transport }}']
discovery.zen.minimum_master_nodes: {{ (elastic_servers | length / 2 + 1) | int }}
{% endif %}

#
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
{% if elastic_version.split('.')[0] == '7' %}
cluster.max_shards_per_node: {{ elastic_arg.cluster_max_shards_per_node | default('1000') }}
{% endif %}
action.destructive_requires_name: {{ elastic_arg.action_destructive_requires_name | bool | to_json }}
http.compression: {{ elastic_arg.http_compression | bool | to_json }}
http.cors.enabled: {{ elastic_arg.http_cors_enabled | bool | to_json }}
http.cors.allow-methods: {{ elastic_arg.http_cors_allow_methods }}
{% if elastic_auth | bool %}
xpack.security.audit.enabled: true
xpack.security.enabled: true
xpack.security.http.ssl.enabled: {{ elastic_https | bool | to_json }}
xpack.security.http.ssl.supported_protocols: TLSv1.2
xpack.security.http.ssl.client_authentication: none
xpack.security.http.ssl.key: /etc/elasticsearch/ssl/server.key
xpack.security.http.ssl.certificate: /etc/elasticsearch/ssl/server.crt
xpack.security.http.ssl.certificate_authorities: /etc/elasticsearch/ssl/ca-cert.pem
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.supported_protocols: TLSv1.2
xpack.security.transport.ssl.client_authentication: none
xpack.security.transport.ssl.verification_mode: none
xpack.security.transport.ssl.key: /etc/elasticsearch/ssl/server.key
xpack.security.transport.ssl.certificate: /etc/elasticsearch/ssl/server.crt
xpack.security.transport.ssl.certificate_authorities: /etc/elasticsearch/ssl/ca-cert.pem
{% endif %}
{% if elastic_node_type == 'coordinat' %}
node.master: false
node.data: false
node.ingest: false
{% elif elastic_node_type == 'master' %}
node.master: true
node.data: false
node.ingest: false
{% elif elastic_node_type == 'data' %}
node.master: false
node.data: true
node.ingest: false
{% elif elastic_node_type == 'ingest' %}
node.master: false
node.data: false
node.ingest: true
{% else %}
{% endif %}
